package com.wisdom.benefit.jufa.main;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CalendarView;

import com.wisdom.benefit.jufa.R;
import com.wisdom.benefit.jufa.base.BaseApplication;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class CalendarViewActivity extends AppCompatActivity {
    CalendarView calendarView;
    private int flag;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calendar_view);
        //初始化
        initView();
        flag = getIntent().getIntExtra("flag", 0);
    }

    /**
     * 初始化
     */
    @SuppressLint("ResourceAsColor")
    private void initView() {
        calendarView = (CalendarView) findViewById(R.id.calenderView);
        calendarView.setFocusedMonthDateColor(R.color.blue);
        //calendarView 监听事件
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
                //显示用户选择的日期
                if (flag == DetailsBalanceActivity.DISTRICT) {
                    Intent intent = new Intent();
                    intent.putExtra("district", year + "年" + (month + 1) + "月" + dayOfMonth + "日");
                    setResult(RESULT_OK, intent);

                } else if (flag == DetailsBalanceActivity.TOWER) {
                    Intent intent = new Intent();
                    intent.putExtra("tower", year + "年" + (month + 1) + "月" + dayOfMonth + "日");
                    setResult(RESULT_OK, intent);

                } else if (flag == 103) {
                    BaseApplication.getContext().setTime(year + "年" + (month + 1) + "月" + dayOfMonth + "日");
                    BaseApplication.getContext().setIsInput("1");
                } else if (flag == 104) {
                    BaseApplication.getContext().setTime(year + "年" + (month + 1) + "月" + dayOfMonth + "日");
                    BaseApplication.getContext().setIsInput("1");
                }
                finish();
            }
        });
    }

}
